cmake_minimum_required(VERSION 2.6)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/..)

set(CMAKE_C_FLAGS "-std=c99")
add_definitions(-DHAVE_AV_CONFIG_H)

set(SOURCES
  4xm.c
  8bps.c
  8svx.c
  a64multienc.c
  aac_ac3_parser.c
  aac_adtstoasc_bsf.c
  aac_parser.c
  aacadtsdec.c
  aaccoder.c
  aacdec.c
  aacenc.c
  aacps.c
  aacpsy.c
  aacsbr.c
  aactab.c
  aandcttab.c
  aasc.c
  ac3.c
  ac3_parser.c
  ac3dec.c
  ac3dec_data.c
  ac3dsp.c
  ac3enc.c
  ac3enc_fixed.c
  ac3enc_float.c
  ac3tab.c
  acelp_filters.c
  acelp_pitch_delay.c
  acelp_vectors.c
  adpcm.c
  adpcm_data.c
  adpcmenc.c
  adx.c
  adx_parser.c
  adxdec.c
  adxenc.c
  alac.c
  alacenc.c
  allcodecs.c
  alsdec.c
  amrnbdec.c
  amrwbdec.c
  anm.c
  ansi.c
  apedec.c
  ass.c
  assdec.c
  assenc.c
  asv1.c
  atrac.c
  atrac1.c
  atrac3.c
  audioconvert.c
  aura.c
  avfft.c
  avpacket.c
  avs.c
  bethsoftvideo.c
  bfi.c
  bgmc.c
  bink.c
  binkaudio.c
  binkdsp.c
  bitstream.c
  bitstream_filter.c
  bmp.c
  bmpenc.c
  bmv.c
  c93.c
  cabac.c
  cavs_parser.c
  cdgraphics.c
  celp_filters.c
  celp_math.c
  cga_data.c
  chomp_bsf.c
  cinepak.c
  cljr.c
  cook.c
  cscd.c
  cyuv.c
  dca.c
  dca_parser.c
  dcadsp.c
  dct.c
  dct32_fixed.c
  dct32_float.c
  dfa.c
  dirac.c
  dirac_parser.c
  dnxhd_parser.c
  dnxhddata.c
  dnxhddec.c
  dnxhdenc.c
  dpcm.c
  dpx.c
  dpxenc.c
  dsicinav.c
  dsputil.c
  dump_extradata_bsf.c
  dv.c
  dvbsub.c
  dvbsub_parser.c
  dvbsubdec.c
  dvdata.c
  dvdsub_parser.c
  dvdsubdec.c
  dvdsubenc.c
  dwt.c
  dxa.c
  dxtory.c
  eac3_data.c
  eac3dec.c
  eac3enc.c
  eacmv.c
  eaidct.c
  eamad.c
  eatgq.c
  eatgv.c
  eatqi.c
  elbg.c
  error_resilience.c
  escape124.c
  faandct.c
  faanidct.c
  faxcompr.c
  fft_fixed.c
  fft_float.c
  ffv1.c
  flac.c
  flac_parser.c
  flacdata.c
  flacdec.c
  flashsv.c
  flashsvenc.c
  flicvideo.c
  flvdec.c
  flvenc.c
  fmtconvert.c
  fraps.c
  frwu.c
  g722.c
  g722dec.c
  g722enc.c
  g726.c
  gif.c
  gifdec.c
  golomb.c
  gsm_parser.c
  gsmdec.c
  gsmdec_data.c
  h261.c
  h261_parser.c
  h261dec.c
  h261enc.c
  h263.c
  h263_parser.c
  h263dec.c
  h264.c
  h264_cabac.c
  h264_cavlc.c
  h264_direct.c
  h264_loopfilter.c
  h264_mp4toannexb_bsf.c
  h264_parser.c
  h264_ps.c
  h264_refs.c
  h264_sei.c
  h264dsp.c
  h264idct.c
  h264pred.c
  huffman.c
  huffyuv.c
  idcinvideo.c
  iff.c
  iirfilter.c
  imc.c
  imgconvert.c
  imx_dump_header_bsf.c
  indeo2.c
  indeo3.c
  indeo4.c
  indeo5.c
  intelh263dec.c
  interplayvideo.c
  intrax8.c
  intrax8dsp.c
  inverse.c
  ituh263dec.c
  ituh263enc.c
  ivi_common.c
  ivi_dsp.c
  jfdctfst.c
  jfdctint.c
  jpegls.c
  jpeglsdec.c
  jpeglsenc.c
  jrevdct.c
  jvdec.c
  kbdwin.c
  kgv1dec.c
  kmvc.c
  lagarith.c
  lagarithrac.c
  latm_parser.c
  lcldec.c
  lclenc.c
  ljpegenc.c
  loco.c
  lpc.c
  lsp.c
  lzw.c
  lzwenc.c
  mace.c
  mdct_fixed.c
  mdct_float.c
  mdec.c
  mimic.c
  mjpeg.c
  mjpeg2jpeg_bsf.c
  mjpeg_parser.c
  mjpega_dump_header_bsf.c
  mjpegbdec.c
  mjpegdec.c
  mjpegenc.c
  mlp.c
  mlp_parser.c
  mlpdec.c
  mlpdsp.c
  mmvideo.c
  motion_est.c
  motionpixels.c
  movsub_bsf.c
  mp3_header_compress_bsf.c
  mp3_header_decompress_bsf.c
  mpc.c
  mpc7.c
  mpc8.c
  mpeg12.c
  mpeg12data.c
  mpeg12enc.c
  mpeg4audio.c
  mpeg4video.c
  mpeg4video_parser.c
  mpeg4videodec.c
  mpeg4videoenc.c
  mpegaudio.c
  mpegaudio_parser.c
  mpegaudiodata.c
  mpegaudiodec.c
  mpegaudiodec_float.c
  mpegaudiodecheader.c
  mpegaudiodsp.c
  mpegaudiodsp_fixed.c
  mpegaudiodsp_float.c
  mpegaudioenc.c
  mpegvideo.c
  mpegvideo_enc.c
  mpegvideo_parser.c
  msgsmdec.c
  msmpeg4.c
  msmpeg4data.c
  msrle.c
  msrledec.c
  msvideo1.c
  mxpegdec.c
  nellymoser.c
  nellymoserdec.c
  nellymoserenc.c
  noise_bsf.c
  nuv.c
  options.c
  pamenc.c
  parser.c
  pcm-mpeg.c
  pcm.c
  pcx.c
  pcxenc.c
  pgssubdec.c
  pictordec.c
  png.c
  pngdec.c
  pngenc.c
  pnm.c
  pnm_parser.c
  pnmdec.c
  pnmenc.c
  proresdec.c
  proresdsp.c
  psymodel.c
  pthread.c
  ptx.c
  qcelpdec.c
  qdm2.c
  qdrw.c
  qpeg.c
  qtrle.c
  qtrleenc.c
  r210dec.c
  ra144.c
  ra144dec.c
  ra144enc.c
  ra288.c
  rangecoder.c
  ratecontrol.c
  raw.c
  rawdec.c
  rawenc.c
  rdft.c
  remove_extradata_bsf.c
  resample.c
  resample2.c
  rl2.c
  rle.c
  roqaudioenc.c
  roqvideo.c
  roqvideodec.c
  roqvideoenc.c
  rpza.c
  rtjpeg.c
  rv10.c
  rv10enc.c
  rv20enc.c
  rv30.c
  rv30dsp.c
  rv34.c
  rv34_parser.c
  rv34dsp.c
  rv40.c
  rv40dsp.c
  s302m.c
  s3tc.c
  sgidec.c
  sgienc.c
  shorten.c
  simple_idct.c
  sinewin.c
  sipr.c
  sipr16k.c
  smacker.c
  smc.c
  snow.c
  snowdec.c
  snowenc.c
  sp5xdec.c
  srtdec.c
  sunrast.c
  svq1.c
  svq1dec.c
  svq1enc.c
  svq3.c
  synth_filter.c
  targa.c
  targaenc.c
  tiertexseqv.c
  tiff.c
  tiffenc.c
  tmv.c
  truemotion1.c
  truemotion2.c
  truespeech.c
  tscc.c
  tta.c
  twinvq.c
  txd.c
  ulti.c
  utils.c
  utvideo.c
  v210dec.c
  v210enc.c
  v210x.c
  v410dec.c
  v410enc.c
  vb.c
  vble.c
  vc1.c
  vc1_parser.c
  vc1data.c
  vc1dec.c
  vc1dsp.c
  vcr1.c
  vmdav.c
  vmnc.c
  vorbis.c
  vorbis_data.c
  vorbisdec.c
  vorbisenc.c
  vp3.c
  vp3_parser.c
  vp3dsp.c
  vp5.c
  vp56.c
  vp56data.c
  vp56dsp.c
  vp56rac.c
  vp6.c
  vp6dsp.c
  vp8.c
  vp8_parser.c
  vp8dsp.c
  vqavideo.c
  wavpack.c
  wma.c
  wmadec.c
  wmaenc.c
  wmaprodec.c
  wmavoice.c
  wmv2.c
  wmv2dec.c
  wmv2enc.c
  wnv1.c
  ws-snd1.c
  #x86/cavsdsp_mmx.c
  #x86/cpuid.c
  #x86/dnxhd_mmx.c
  #x86/dsputil_h264_template_mmx.c
  #x86/dsputil_h264_template_ssse3.c
  #x86/dsputil_mmx.c
  #x86/dsputil_mmx_avg_template.c
  #x86/dsputil_mmx_qns_template.c
  #x86/dsputil_mmx_rnd_template.c
  #x86/dsputilenc_mmx.c
  #x86/fdct_mmx.c
  #x86/fft.c
  #x86/fft_3dn.c
  #x86/fft_3dn2.c
  #x86/fft_sse.c
  #x86/h264dsp_mmx.c
  #x86/idct_mmx.c
  #x86/idct_mmx_xvid.c
  #x86/idct_sse2_xvid.c
  #x86/lpc_mmx.c
  #x86/mlpdsp.c
  #x86/motion_est_mmx.c
  #x86/mpegvideo_mmx.c
  #x86/mpegvideo_mmx_template.c
  #x86/rv40dsp_mmx.c
  #x86/simple_idct_mmx.c
  #x86/snowdsp_mmx.c
  #x86/vc1dsp_mmx.c
  #x86/vp3dsp_mmx.c
  #x86/vp3dsp_sse2.c
  #x86/vp6dsp_mmx.c
  #x86/vp6dsp_sse2.c
  xan.c
  xiph.c
  xl.c
  xsubdec.c
  xsubenc.c
  xxan.c
  yop.c
  zmbv.c
  zmbvenc.c
)

if(SPEEX_FOUND)
  list(APPEND SOURCES libspeexdec.c)
endif()

if(FAAC_FOUND)
  list(APPEND SOURCES libfaac.c)
endif()

if(FAAD_FOUND)
  list(APPEND SOURCES libfaad.c)
endif()

if(XVID_FOUND)
  list(APPEND SOURCES
    libxvid_rc.c
    libxvidff.c
  )
endif()

if(WINDOWS)
  list(APPEND SOURCES w32thread.c)
endif()

add_library(avcodec SHARED ${SOURCES})

target_link_libraries(avcodec
  avutil
  ${VORBIS_LIBRARIES}
  ${VORBISENC_LIBRARIES}
  ${LAME_LIBRARIES}
  ${SPEEX_LIBRARIES}
  ${THEORA_LIBRARIES}
  ${THEORAENC_LIBRARIES}
  z)

if(FAAC_FOUND)
  target_link_libraries(avcodec ${FAAC_LIBRARIES})
endif()

if(FAAC_FOUND)
  target_link_libraries(avcodec ${FAAD_LIBRARIES})
endif()

if(XVID_FOUND)
  target_link_libraries(avcodec ${XVID_LIBRARIES})
endif()

install(TARGETS avcodec
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)